package com.liuxu.topnews.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.liuxu.topnews.MyApplication;


public class AndroidUtils {
    static final String TAG = AndroidUtils.class.getSimpleName();
    private static String sDeviceId;
    private static int sDisplayHeight = 0;
    private static int sDisplayWidth = 0;
    private static String sScreenRate;
    private static int statusBarHeight = 0;

    private AndroidUtils() {
    }

//    public static void callHTTPDownload(Context var0, String var1, String var2) {
//        if (var0 != null) {
//            Context var3 = var0;
//            if (isActivityContext(var0)) {
//                var3 = StubApp.getOrigApplicationContext(var0.getApplicationContext());
//            }
//
//            Intent var5 = new Intent("android.readintent.action.VIEW");
//            var5.setData(Uri.parse(URLUtil.guessUrl(var2)));
//
//            try {
//                var3.startActivity(Intent.createChooser(var5, var1).addFlags(268435456));
//            } catch (Exception var4) {
//                ToastUtils.getInstance().show("没有合适的应用打开链接");
//            }
//        }
//    }

    public static void callPhone(Context var0, String var1) {
        if (var0 != null && isCanUseSim(var0)) {
            try {
                Intent var2 = new Intent();
                var2.setAction("android.readintent.action.DIAL");
                if (!isActivityContext(var0)) {
                    var2.addFlags(268435456);
                }

                var2.setData(Uri.parse("tel:" + var1));
                var0.startActivity(var2);
            } catch (ActivityNotFoundException var3) {
                var3.printStackTrace();
            }
        }
    }

    public static int dip2px(float var0) {
        return (int)(var0 * MyApplication.getContext().getResources().getDisplayMetrics().density + 0.5F);
    }

    public static int getAndroidSDKVersion() {
        return Build.VERSION.SDK_INT;
    }

    public static int getAppVersionCode() {
        try {
            int var0 = MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionCode;
            return var0;
        } catch (Exception var2) {
            LogUtil.getInstance().show("getAppVersionCode Exception: " + var2.getMessage());
            return 0;
        }
    }

    public static String getAppVersionName(String param0) {
        // $FF: Couldn't be decompiled
        return "no";
    }

    public static String getCurProcessName(Context param0) {
        // $FF: Couldn't be decompiled
        return "no";
    }

    public static float getDensity() {
        return MyApplication.getContext().getResources().getDisplayMetrics().density;
    }

    public static float getDensityDpi() {
        return (float)MyApplication.getContext().getResources().getDisplayMetrics().densityDpi;
    }

//    public static String getDeviceId() {
//        if (sDeviceId == null) {
//            sDeviceId = (new DeviceUuidFactory(MyApplication.getContext())).getDeviceUuid();
//        }
//
//        return sDeviceId;
//    }

    public static String getDeviceResolution() {
        return getDeviceResolution("x");
    }

    @SuppressLint({"DefaultLocale"})
    public static String getDeviceResolution(String var0) {
        return String.format("%d%s%d", getDisplayWidth(), var0, getDisplayHeight());
    }

    private static void getDisplay() {
        if (sDisplayWidth <= 0 || sDisplayHeight <= 0) {
            WindowManager var0 = (WindowManager)MyApplication.getContext().getSystemService("window");
            DisplayMetrics var1 = new DisplayMetrics();
            var0.getDefaultDisplay().getMetrics(var1);
            sDisplayWidth = var1.widthPixels;
            sDisplayHeight = var1.heightPixels;
        }

    }

    public static int getDisplayHeight() {
        getDisplay();
        return sDisplayHeight;
    }

    public static int getDisplayWidth() {
        getDisplay();
        return sDisplayWidth;
    }

//    public static String getIMEI() {
//        requestPermission("android.permission.READ_PHONE_STATE");
//        TelephonyManager var0 = (TelephonyManager)MyApplication.getContext().getSystemService("phone");
//        return var0 == null ? null : var0.getDeviceId();
//    }

    public static void getMetaData(String param0) {
        // $FF: Couldn't be decompiled
    }

    public static String getScreenRate() {
        if (sScreenRate == null) {
            int var0 = getDisplayWidth();
            int var1 = getDisplayHeight();
            sScreenRate = var0 + "_" + var1;
        }

        return sScreenRate;
    }

    public static int getStatusBarHeight() {
        return 0;
    }


    public static boolean isActivityContext(Context var0) {
        return var0 instanceof Activity;
    }

    public static boolean isCanUseSim(Context var0) {
        return 5 == ((TelephonyManager)var0.getSystemService("phone")).getSimState();
    }

    public static boolean isCellPhone(Context param0) {
        // $FF: Couldn't be decompiled
        return false;
    }

    public static boolean isMainProcess(Context var0) {
        String var1 = var0.getPackageName();
        String var2 = getCurProcessName(var0);
        return TextUtils.isEmpty(var2) || var2.equals(var1);
    }

    public static boolean isMainThread() {
        return Looper.myLooper() == Looper.getMainLooper();
    }

//    public static void locate(Context var0, String var1, String var2, String var3, String var4) {
//        if (var0 != null) {
//            Context var5 = var0;
//            if (isActivityContext(var0)) {
//                var5 = StubApp.getOrigApplicationContext(var0.getApplicationContext());
//            }
//
//            Intent var6 = new Intent();
//            var6.setAction("android.readintent.action.VIEW");
//            var2 = "geo:0,0?q=" + var2 + "," + var3;
//            String var8 = var2;
//            if (var4 != null) {
//                var8 = var2;
//                if (var4.length() > 0) {
//                    var8 = var2 + "(" + var4 + ")";
//                }
//            }
//
//            var6.setData(Uri.parse(var8));
//
//            try {
//                var5.startActivity(Intent.createChooser(var6, var1).addFlags(268435456));
//            } catch (Exception var7) {
//                ToastUtils.show("没有合适的应用打开位置信息");
//            }
//        }
//    }

    public static int px2dip(float var0) {
        return (int)(var0 / MyApplication.getContext().getResources().getDisplayMetrics().density + 0.5F);
    }

    public static void requestPermission(String var0) {
        Application var1 = MyApplication.getApplication();
        if (var1.getPackageManager().checkPermission(var0, var1.getPackageName()) != 0) {
            throw new UnsupportedOperationException("missing permission \"android.permission.READ_PHONE_STATE \" in manifest.xml!");
        }
    }
}
